//Component Object
import {
  storeBindingsBehavior
} from "mobx-miniprogram-bindings";
import base from "@src/store/base";
Component({
  behaviors: [storeBindingsBehavior],
  storeBindings: [{
      store: base,
      fields: ['themeColor', 'themeTitleColor']
  }],
  properties: {
    slots: {
      type: Array,
      value: [],
    }, //{title,sName}
    tabsheight: {
      type: String,
      value: '100vh'
    },
    currentTabIdx: {
      type: Number,
      value: 0,
      observer: function (v) {
        this.setData({
          currentTab: v,
          navScrollLeft: v >= 4 ? (v * 60) : 0
        })
      }
    },
    isRefresherTriggered: {
      type: Boolean,
      value: false,
      observer: function (v) {
        this.setData({
          isRefresher: false
        })
      }
    }
  },
  options: {
    multipleSlots: true
  },
  data: {
    currentTab: 0,
    isRefresher: true
  },
  methods: {
    tabsHeight(element) {
      let that = this;
      let query = wx.createSelectorQuery();
      query.select(element).boundingClientRect(function (rect) {
        that.setData({
          tabsheight: rect.height + 'px'
        });
      }).exec();
    },
    swichNav: function (e) {
      var that = this;
      if (this.data.currentTab === e.target.dataset.current) {
        return false;
      } else {
        that.setData({
          currentTab: e.target.dataset.current,
          navScrollLeft: e.target.dataset.current >= 4 ? ((e.target.dataset.current) * 60) : 0
        })
      }
      // that.tabsHeight('.swiper-tab-list' + e.target.dataset.current);
      // that.triggerEvent('changeTab', this.data.currentTab);
    },
    bindChange: function (e) {
      var that = this;
      that.setData({
        currentTab: e.detail.current,
        navScrollLeft: e.detail.current >= 4 ? ((e.detail.current) * 60) : 0
      });
      // that.tabsHeight('.swiper-tab-list' + e.detail.current);
      that.triggerEvent('changeTab', this.data.currentTab);
    },
    lower(e) {
      e && this.triggerEvent('bringUp', true);
    },
    loadData(e) {
      e && this.triggerEvent('loadData', true);
    }
  },
});